package com.dididoctor.doctor.Activity.Order;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dididoctor.doctor.MV.EduActivity;
import com.dididoctor.doctor.R;
import com.netease.nim.uikit.session.activity.P2PMessageActivity;

/**
 * @version 2.0
 * @类描述： 登陆页
 * @项目名称：ddgh
 * @类名称： loginActivity
 * @包名称： com.doudoukeji.service.Activity.login
 * @创建人：张强 boy
 * @创建时间：2016/3/7 16:40
 * @修改人：
 * @修改时间：2016/3/7 16:40
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class OrderTabFragActivity extends EduActivity {
    private Fragment[] fgs;
    private int curPos = 0;
    private TextView[] textViews;
    private final int textViewIds[] = new int[]{
            R.id.tv_title1, R.id.tv_title2
    };
    private final int layoutIds[] = new int[]{
            R.id.layout1, R.id.layout2
    };

    private String schoolname;
    private ViewPager viewPager;

    @Override
    public void setContentLayout() {
        setContentView(R.layout.forum_tab_frg);
        schoolname = getIntent().getStringExtra("schoolname");
    }


    @Override
    public void init() {
        initTopbar();

        textViews = new TextView[2];
        LinearLayout[] layouts = new LinearLayout[2];
        for (int i = 0; i < 2; i++) {
            textViews[i] = (TextView) findViewById(textViewIds[i]);
            layouts[i] = (LinearLayout) findViewById(layoutIds[i]);
            layouts[i].setOnClickListener(this);
        }

        viewPager = (ViewPager) findViewById(R.id.frg_layout);
        Fragment forumModuleFragment = new OrderModuleFragment("0");
        Fragment schoolQuesFragment = new OrderModuleFragment("1");
        P2PMessageActivity p2PMessageActivity = new P2PMessageActivity();

        fgs = new Fragment[]{forumModuleFragment, schoolQuesFragment};

        viewPager.setAdapter(new ForumTabAdapter(getSupportFragmentManager()));
        viewPager.setOffscreenPageLimit(2);
        viewPager.setCurrentItem(0);
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                select(i);
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });

    }

    private void select(int i) {
        if (curPos != i) {
            textViews[curPos].setTextColor(Color.parseColor("#fcb314"));
            textViews[i].setTextColor(Color.parseColor("#ffffff"));
            textViews[i].setBackgroundColor(Color.parseColor("#fcb314"));
            textViews[curPos].setBackgroundColor(Color.parseColor("#ffffff"));
            curPos = i;
        }

        switch (i) {
            case 1:
                break;
            case 0:
            case 2:

                break;
        }
    }

    private void initTopbar() {
    }

    @Override
    public void onClickEvent(View view) {
        int id = view.getId();
        switch (id) {

        }

        if (id == layoutIds[0]) {
            select(0);
            viewPager.setCurrentItem(0);
        } else if (id == layoutIds[1]) {
            viewPager.setCurrentItem(1);
            select(1);
        } else if (id == layoutIds[2]) {
            viewPager.setCurrentItem(2);
            select(2);
        }
    }


    class ForumTabAdapter extends FragmentPagerAdapter {

        public ForumTabAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            return fgs[i];
        }

        @Override
        public int getCount() {
            return fgs.length;
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
